package com.chase.passwordmaster.utils

import android.content.Context
import android.content.Context.VIBRATOR_SERVICE
import android.os.Vibrator

private const val VIBRATE_MILLI_SECOND = 20

private var vibrator: Vibrator? = null
/**
 * @ClassName:VibrateHelp - 简单的震动
 * @author:CaoJiaHao
 * @Param:context 调用震动类的 context
 * @param:millisecond 震动的时间
 */
fun vSimple(context: Context, millisecond: Int) {
    vibrator = context.getSystemService(VIBRATOR_SERVICE)?.let { it as Vibrator }
    vibrator?.vibrate(millisecond.toLong())
}

/**
 * @param : pattern 震动的形式
 * @param : repeate 震动循环的次数
 * @ClassName:VibrateHelp - 复杂的震动
 * @author:CaoJiaHao
 * @Param: context 调用复杂震动的context
 */
fun vComplicated(context: Context, pattern: LongArray, repeat: Int) {
    vibrator = context.getSystemService(VIBRATOR_SERVICE)?.let { it as Vibrator }
    vibrator?.vibrate(pattern, repeat)
}

/**
 * @ClassName:VibrateHelp - 停止震动
 * @author:CaoJiaHao
 */
fun stop() {
    vibrator?.cancel()
}

fun Context.vibrate(millisecond: Int = VIBRATE_MILLI_SECOND) {
    return
    // vSimple(this, millisecond = millisecond)
}
fun Context.vibrate(pattern: LongArray, repeat: Int) = vComplicated(this, pattern, repeat)